/**
 * @description: 项目初始化
 * @fileName: index
 * @author: luhuixu
 * @date: 2023/4/26-15:05
 * @version: V1.0.0
 **/
// 加载app初始化数据
import router from '../router'
import { queryDictionary } from '@/api/system'

export default {
  init(options) {
    router.beforeEach(async(to, from, next) => {
      if (options.enable && (from.path === '/login' || sessionStorage.getItem('gender') === null)) {
        // 保存字典
        queryDictionary({ list: [] }).then(res => {
          for (const dataKey in res.data) {
            const dic = res.data[dataKey]
            dic?.forEach(item => {
              sessionStorage.setItem(dataKey, JSON.stringify(item.child))
            })
          }
          // console.log('res-data', res.data,)
        })
      }
      next()
    })
  }
}
